from PyQt5.QtWidgets import QDialog, QApplication, QDialogButtonBox

from ui_ticketorder import Ui_Dialog
import datetime


class Form(QDialog, Ui_Dialog):
    def __init__(self, parent=None):
        super(Form, self).__init__(parent)
        self.setupUi(self)
        self.dbxPrice.valueChanged.connect(self.updateUI)
        self.spxQuanify.valueChanged.connect(self.updateUI)
        self.customLineEdit.textChanged.connect(self.updateUI)

        self.updateUI()

    def updateUI(self):
        now = datetime.datetime.now()
        tomorrow = datetime.datetime(now.year, now.month, now.day + 1)
        nextyear = datetime.datetime(now.year + 1, now.month, now.day)
        self.dateTimeEdit.setMaximumDate(nextyear)
        self.dateTimeEdit.setMinimumDate(tomorrow)
        self.txtAmount.setText(str(self.dbxPrice.value() * self.spxQuanify.value()))

        enable = len(self.customLineEdit.text()) > 0 and int(self.spxQuanify.text()) > 0
        self.b.button(QDialogButtonBox.Ok).setEnabled(enable)

    def result(self):
        print(self.customLineEdit.text(), self.dateTimeEdit.text(), self.txtAmount.text())


if __name__ == '__main__':
    import sys

    app = QApplication(sys.argv)
    form = Form()
    form.show()
    form.result()
    sys.exit(app.exec())
